package com.lei.zktwo;

import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.lei.mvptwozk.mvp.view.BaseActivty;
import com.lei.zktwo.mvp.contract.LoginContract;
import com.lei.zktwo.mvp.model.LoginModel;
import com.lei.zktwo.mvp.presenter.LoginPresenter;

public class RegisterActivity extends BaseActivty<LoginPresenter> implements LoginContract.RegisterView {
    private EditText etAppkeyRegiste;
    private EditText etNameRegiste;
    private EditText etPasswdRegiste;
    private Button btRegister;
    private LoginPresenter loginPresenter;

    @Override
    public int bindlayout() {
        return R.layout.activity_register;
    }

    @Override
    public void initview() {
        Intent intent = getIntent();
        String appkey = intent.getStringExtra("appkey");
        etAppkeyRegiste = (EditText) findViewById(R.id.et_appkey_registe);
        etNameRegiste = (EditText) findViewById(R.id.et_name_registe);
        etPasswdRegiste = (EditText) findViewById(R.id.et_passwd_registe);
        btRegister = (Button) findViewById(R.id.bt_register);
        etAppkeyRegiste.setText(appkey);
        btRegister.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                loginPresenter.register();
            }
        });
    }

    @Override
    public void inject() {
        loginPresenter = new LoginPresenter(new LoginModel(),this);
    }

    @Override
    public String getkey() {
        return etAppkeyRegiste.getText().toString().trim();
    }

    @Override
    public String getname() {
        return etNameRegiste.getText().toString().trim();
    }

    @Override
    public String getpasswd() {
        return etPasswdRegiste.getText().toString().trim();
    }

    @Override
    public void gomain(String json) {
        Toast.makeText(this, json + "", Toast.LENGTH_SHORT).show();
        Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
        intent.putExtra("appkey",getkey());
        intent.putExtra("name",getname());
        intent.putExtra("pwd",getpasswd());
        startActivity(intent);
    }
}
